package com.globopt.global.algorithm.functions;

import com.globopt.global.algorithm.Function;
import com.globopt.global.algorithm.Point;

/**
 * Sample test function.
 * 
 * @author Richard Gasztany 2012.11.25.
 * 
 */
public class F3 extends Function {

	public F3() {
		this.nvars = 3;
	}

	@Override
	public double evaluation(Point p) {
		double x = p.getCoordinate(0);
		double y = p.getCoordinate(1);
		double z = p.getCoordinate(2);
		double ret = 0.0;

		for (int i = 1; i <= 10; i++) {
			ret += Math.cos(x / i) + Math.sin(y / i) + Math.pow(z, i) / factorial(i);
		}
		return ret;
	}

	private double factorial(int k) {
		double ret = 1.0;
		for (int i = 1; i <= k; i++) {
			ret *= i;
		}
		return ret;
	}
}
